package main

import (
	"fmt"
	"os"
	"os/exec"
	"runtime"
)

func main() {
	// 图片URL（可替换为任意网络图片地址）
	imageURL := "https://eb118-file.cdn.bcebos.com/upload/f63c234de27f4cafba63d7d2b26aa348_1202535461.png?"

	// 生成HTML内容
	htmlContent := fmt.Sprintf(`
<!DOCTYPE html>
<html>
<head>
	<title>海绵宝宝图片</title>
	<style>
		body {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100vh;
			margin: 0;
			background-color: #f0f8ff;
		}
		img {
			border: 5px solid #FFD700;
			border-radius: 10px;
			box-shadow: 0 0 20px rgba(0,0,0,0.3);
		}
	</style>
</head>
<body>
	<img src="%s" alt="海绵宝宝" width="600">
</body>
</html>
`, imageURL)

	// 保存HTML文件
	fileName := "spongebob.html"
	err := os.WriteFile(fileName, []byte(htmlContent), 0644)
	if err != nil {
		panic(err)
	}

	// 自动打开浏览器
	openBrowser(fileName)
	fmt.Println("已生成图片链接页面:", fileName)
}

// 跨平台打开浏览器
func openBrowser(file string) {
	switch runtime.GOOS {
	case "linux":
		exec.Command("xdg-open", file).Start()
	case "windows":
		exec.Command("rundll32", "url.dll,FileProtocolHandler", file).Start()
	case "darwin":
		exec.Command("open", file).Start()
	}
}
